<?php

	// TITLE: Interest_type AUTO MODEL
	// FILE: scaffolding/model/interest_type.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createInterestType = function($con, $interestType) {
		$sql = 'INSERT INTO interest_type (id, title, code, description) VALUES (';
		$sql .= $interest_type->getId() . ', ';
		$sql .= $interest_type->getTitle() . ', ';
		$sql .= $interest_type->getCode() . ', ';
		$sql .= $interest_type->getDescription() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readInterestType = function($con, $id) {
		$sql = 'SELECT * FROM interest_type WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$interestType = new InterestType();
			$interestType->setId(result[0]);
			$interestType->setTitle(result[1]);
			$interestType->setCode(result[2]);
			$interestType->setDescription(result[3]);
		} else {
			$interestType = false;
		}
		return $interestType;
	};

	$updateInterestType = function($con, $interestType) {
		$sql = 'UPDATE interest_type SET ';
		$sql .= 'id = ' . $interest_type->getId() . ', ';
		$sql .= 'title = ' . $interest_type->getTitle() . ', ';
		$sql .= 'code = ' . $interest_type->getCode() . ', ';
		$sql .= 'description = ' . $interest_type->getDescription() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteInterestType = function($con, $id) {
		$sql = 'DELETE FROM interest_type WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listInterestType = function($con) {
		$sql = 'SELECT * FROM interest_type';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$interestTypes = array();
			while ($result = mysqli_fetch_array($results)) {
				$interestType = new InterestType();
				$interestType->setId(result[0]);
				$interestType->setTitle(result[1]);
				$interestType->setCode(result[2]);
				$interestType->setDescription(result[3]);
				$interestTypes[] = interestType;
			}// end while
		} else {
			$interestTypes = false;
		}
		return $interestTypes;
	};

